package org.linlinjava.litemall.db.service;

import java.time.LocalDateTime;
import java.util.List;

import javax.annotation.Resource;

import org.linlinjava.litemall.db.dao.LitemallRefundTaxMapper;
import org.linlinjava.litemall.db.dao.RefundTaxMapper;
import org.linlinjava.litemall.db.domain.LitemallRefundTax;
import org.linlinjava.litemall.db.domain.LitemallRefundTaxExample;
import org.linlinjava.litemall.db.domain.ShopRefundListQuery;
import org.linlinjava.litemall.db.domain.TaxStatisticsDetailVo;
import org.springframework.stereotype.Service;

@Service
public class LitemallRefundTaxService {
	
    @Resource
    private LitemallRefundTaxMapper litemallRefundTaxMapper;
    @Resource
    private RefundTaxMapper refundTaxMapper;
    
    public LitemallRefundTax findById(Integer id) {
    	return litemallRefundTaxMapper.selectByPrimaryKey(id);
    }

    public void add(LitemallRefundTax refundTax) {
    	refundTax.setAddTime(LocalDateTime.now());
    	litemallRefundTaxMapper.insertSelective(refundTax);
    }
    
    public void update(LitemallRefundTax refundTax) {
    	litemallRefundTaxMapper.updateByPrimaryKeySelective(refundTax);
    }
    
    public List<LitemallRefundTax> findByRefundIdAndRefundGoodsId(Integer refundId, Integer refundGoodsId){
   	 	LitemallRefundTaxExample example = new LitemallRefundTaxExample();
        example.or().andRefundIdEqualTo(refundId).andRefundGoodsIdEqualTo(refundGoodsId).andDeletedEqualTo(false);
        
        return litemallRefundTaxMapper.selectByExample(example);
   }
    
    public List<TaxStatisticsDetailVo> statistics(String startTime, String endTime, Integer shopId) {
    	return refundTaxMapper.statistics(startTime, endTime, shopId);
    }
    
    public List<TaxStatisticsDetailVo> totalStatistics(String startTime, String endTime, Integer regionId) {
    	return refundTaxMapper.totalStatistics(startTime, endTime, regionId);
    }
    
    public List<TaxStatisticsDetailVo> proxyStatistics(String startTime, String endTime, Integer shopId) {
    	return refundTaxMapper.proxyStatistics(startTime, endTime, shopId);
    }
    
    public List<TaxStatisticsDetailVo> proxyTotalStatistics(String startTime, String endTime, Integer regionId) {
    	return refundTaxMapper.proxyTotalStatistics(startTime, endTime, regionId);
    }
    
    public List<TaxStatisticsDetailVo> queryByRefundId(Integer refundId) {
    	return refundTaxMapper.queryByRefundId(refundId);
    }
    
    public List<TaxStatisticsDetailVo> totalShopStatistic(ShopRefundListQuery query) {
    	return refundTaxMapper.totalShopStatistic(query);
    }

}
